package com.vf.admin.client.controller;

import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.common.ClientConstants;
import com.vf.admin.client.common.RedisKeys;
import com.vf.admin.client.service.*;
import com.vf.admin.client.tx.vo.UserShiZhi;
import com.vf.admin.common.Constants;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.redis.RedisUtil;
import com.vf.admin.fiwork.controller.AppDailyTasController;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.utils.ExpressionFilter;
import com.vf.admin.utils.StringEx;
import com.vf.admin.utils.aliyunoss.OssCheckUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.vf.admin.client.tx.utils.TxIm.portraitNiChengSet;
import static com.vf.admin.client.tx.utils.TxIm.portraitTouXiangSet;
import static com.vf.admin.utils.StringEx.isNull;
import static com.vf.admin.utils.sensitiveword.minganci.sensitiveWordDetection;

/**
 * 个人信息
 *
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppGeRenxinxiController.java
 * @Description TODO
 * @createTime 2021年07月21日 11:14:00
 */
@CrossOrigin
@Controller
@RequestMapping("/app/geren")
public class AppGeRenxinxiController extends ClientBaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    AppUserService appUserService;
    @Autowired
    AppTaskRecordService appTaskRecordService;
    @Autowired
    AppZhiyeFuService appZhiyeFuService;
    @Autowired
    AppZhiyeService appZhiyeService;
    @Autowired
    AppSsCitiesService appSsCitiesService;
    @Autowired
    AppSsProvincesService appSsProvincesService;
    @Autowired
    AppBiaoqianService appBiaoqianService;
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    private AppDailyTasController appDailyTasController;
    @Autowired
    private SsAreaService areaService;
    @Autowired
    private AgentUserRecordsService agentUserRecordsService;
    @Autowired
    private AgentUserService agentUserService;

    /**
     * 修改，保存昵称
     *
     * @Param: [nicheng  昵称]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/21
     */
    @RequestMapping("/upnick")
    @ResponseBody
    public Result upnick(String nick) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(nick)) {
                return this.errorJSON("昵称不能为空");
            }
            if (nick.toLowerCase().contains("script")) {
                return this.errorJSON("请不要做非法攻击！");
            }
            if (StringEx.isNotNull(nick)) {
                if (nick.length() > 8) {
                    return this.errorJSON("昵称长度过长");
                }
                if (ExpressionFilter.expressionJudgment(nick)) {
                    return this.errorJSON("昵称不能包含特殊字符");
                }
            }
//            if (sensitiveWordDetection(nick, Constants.keyWordSet)) {
//                return this.errorJSON("昵称包含敏感词汇!");
//            }
            System.out.println(System.currentTimeMillis());
            for (Object object : Constants.jsonArray) {
                if (nick.contains(object.toString())) {
                    System.out.println(System.currentTimeMillis());
                    return this.errorJSON("内容不能包含敏感词BBB");
                }
            }
            appUserService.upnick(user.getId(), nick);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            //腾讯三方导入
            UserShiZhi shiZhi = new UserShiZhi();
            shiZhi.setNicheng(nick);
            shiZhi.setTengxuncode(user.getTengxuncode() + "");
            portraitNiChengSet(shiZhi);
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改昵称异常", e);
            return this.errorJSON("系统繁忙");
        }
    }


    /**
     * 修改，保存个性签名
     *
     * @Param: [mysign 个性签名]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/21
     */
    @RequestMapping("/upmysign")
    @ResponseBody
    public Result upMysign(String mysign) {
        try {

            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(mysign)) {
                return this.errorJSON("个性签名不能为空");
            }
            if (StringEx.isNotNull(mysign)) {
                if (mysign.length() > 50) {
                    return this.errorJSON("字数在50字以内");
                }
            }
            for (Object object : Constants.jsonArray) {
                if (mysign.contains(object.toString())) {
                    return this.errorJSON("内容不能包含敏感词");
                }
            }
            if (mysign.toLowerCase().contains("script")) {
                return this.errorJSON("请不要做非法攻击！");
            }

            appUserService.upMysign(user.getId(), mysign);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改个性签名异常", e);
            return this.errorJSON("系统繁忙");
        }
    }


    /**
     * 编辑支付宝号，姓名信息
     *
     * @Param: [name 收款人（支付宝绑定的人）, alipay 支付宝号]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/21
     * @Time: 17:39
     */
    @RequestMapping("/upAlipay")
    @ResponseBody
    public Result upAlipay(String name, String alipay) {
        try {

            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);
            if (StringEx.isNotNull(user.getShoukuanren()) && StringEx.isNotNull(user.getAlipay())) {
                return this.errorJSON("绑定过不可更改");
            }
            if (isNull(name)) {
                return this.errorJSON("真实姓名不能为空");
            }
            if (isNull(alipay)) {
                return this.errorJSON("支付宝号不能为空");
            }
            if (name.toLowerCase().contains("script")) {
                return this.errorJSON("请不要做非法攻击！");
            }
            if (alipay.toLowerCase().contains("script")) {
                return this.errorJSON("请不要做非法攻击！");
            }

            appUserService.upAlipay(user.getId(), name, alipay);
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改姓名，支付宝信息异常", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    /**
     * 获取省市信息列表
     *
     * @Param: []
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/21
     * @Time: 17:59
     */
    @RequestMapping("/sslist")
    @ResponseBody
    public Result sslist() {
        try {
            //获取省份
            List<SsProvinces> list = appSsProvincesService.list();
            //获取市
            List<SsCities> shiList = appSsCitiesService.list();
            List<SsArea> areaList = areaService.list();
            for (SsProvinces ssProvinces : list) {
                List<SsCities> citiesList = new ArrayList<>();
                for (SsCities ssCities : shiList) {
                    if (ssCities.getProvinceid().equals(ssProvinces.getProvinceid())) {
                        List<SsArea> areaList1 = new ArrayList<>();
                        for (SsArea a : areaList) {
                            if (a.getParentId().equals(ssCities.getCityid())) {
                                areaList1.add(a);
                            }
                        }
                        ssCities.setAreaList(areaList1);
                        citiesList.add(ssCities);
                    }
                }
                ssProvinces.setCitiesList(citiesList);
            }
            Map<String, Object> toMap = new HashMap<>(16);
            toMap.put("list", list);
            return this.sucessJSON(toMap, "成功");
        } catch (Exception e) {
            logger.error("获取省市列表异常", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    @RequestMapping("/sslistIndex")
    @ResponseBody
    public Result sslistIndex() {
        try {
            //获取省份
            List<SsProvinces> provincesList = new ArrayList<>();

            List<SsCities> shiList1 = new ArrayList<>();
            SsCities ssCities1 = new SsCities();
            ssCities1.setCity("不限");
            shiList1.add(ssCities1);

            SsProvinces ssProvinces1 = new SsProvinces();
            ssProvinces1.setProvince("不限");
            ssProvinces1.setCitiesList(shiList1);

            provincesList.add(ssProvinces1);
            List<SsProvinces> list = appSsProvincesService.list();
            provincesList.addAll(list);

            //获取市
            List<SsCities> shiList = appSsCitiesService.list();
            List<SsArea> areaList = areaService.list();
            for (SsProvinces ssProvinces : provincesList) {
                List<SsCities> citiesList = new ArrayList<>();
                for (SsCities ssCities : shiList) {
                    if (ssProvinces.getProvinceid() != null && ssCities.getProvinceid().equals(ssProvinces.getProvinceid())) {
                        List<SsArea> areaList1 = new ArrayList<>();
                        for (SsArea a : areaList) {
                            if (a.getParentId().equals(ssCities.getCityid())) {
                                areaList1.add(a);
                            }
                        }
                        ssCities.setAreaList(areaList1);
                        citiesList.add(ssCities);
                    }
                }
                if (ssProvinces.getProvinceid() != null) {
                    ssProvinces.setCitiesList(citiesList);
                }
            }
            Map<String, Object> toMap = new HashMap<>(16);
            toMap.put("list", provincesList);
            return this.sucessJSON(toMap, "成功");
        } catch (Exception e) {
            logger.error("获取省市列表异常", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    private static Map<String, Object> change(List<Map<String, Object>> list, String oneMapKey) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Set setTmp = new HashSet();
        for (Map<String, Object> tmp : list) {
            setTmp.add(tmp.get(oneMapKey));
        }
        Iterator it = setTmp.iterator();
        while (it.hasNext()) {
            String oneSetTmpStr = (String) it.next();
            List<Map<String, Object>> oneSetTmpList = new ArrayList<Map<String, Object>>();
            for (Map<String, Object> tmp : list) {
                String oneMapValueStr = (String) tmp.get(oneMapKey);
                if (oneMapValueStr.equals(oneSetTmpStr)) {
                    oneSetTmpList.add(tmp);
                }
            }
            resultMap.put(oneSetTmpStr, oneSetTmpList);
        }
        return resultMap;
    }

    /**
     * 编辑地址信息
     *
     * @Param: [provinceid 省编码, cityid 市编码]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/21
     * @Time: 18:13
     */
    @RequestMapping("/saveaddress")
    @ResponseBody
    public Result saveaddress(Integer provinceid, Integer cityid, Integer areaId) {
        try {

            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(provinceid)) {
                return this.errorJSON("未获取到省编码");
            }
            if (isNull(cityid)) {
                return this.errorJSON("未获取到城市编码");
            }
            SsCities ssCities = appSsCitiesService.getCitie(cityid);
            if (org.springframework.util.StringUtils.isEmpty(ssCities)) {
                return this.errorJSON("未获取到城市");
            }
            appUserService.upAddress(user.getId(), ssCities.getCity(), ssCities.getCityid(), ssCities.getProvinceid(), areaId);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }

            AgentUserRecords exist = agentUserRecordsService.exist(userId);
            if (exist == null) {
                AgentUser userByAreaId = agentUserService.findUserByAreaId(areaId);
                if (userByAreaId != null) {
                    agentUserRecordsService.save(userByAreaId.getId(), userId);
                }
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("编辑地址时异常", e);
            return this.errorJSON("系统繁忙");
        }
    }


    /**
     * 修改生日信息
     *
     * @Param: [birthday 日期（yyyy-MM-dd）]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/21
     * @Time: 18:57
     */
    @RequestMapping("/upbirthday")
    @ResponseBody
    public Result upbirthday(String birthday) {
        try {

            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(birthday)) {
                return this.errorJSON("生日不能为空");
            }
            DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
            appUserService.upbirthday(user.getId(), format1.parse(birthday));
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("编辑生日时异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 编辑头像
     *
     * @Param: [image 头像文件流]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/22
     * @Time: 9:39
     */
    @RequestMapping("/uppic")
    @ResponseBody
    public Result uppic(MultipartFile[] image, String pic) {
        try {

            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (ObjectUtil.isEmpty(pic) && (image != null && image.length > 0)) {
                //上传：循环获取file数组中得文件
                StringBuffer stringBuffer = new StringBuffer();
                MultipartFile files = image[0];
                if (!files.isEmpty()) {
                    //判断图片大小
                    if (files.getSize() <= 52428800) {
                        //上传阿里云oss
                        String ossUrl = appUserService.aliyunOssupload(files);
                        if (isNull(ossUrl)) {
                            return errorJSON("图片上传失败");
                        }
                        //拼接
                        stringBuffer.append(ossUrl);
                    } else {
                        return this.errorJSON("图片大小超过限制！");
                    }
                }
                pic = stringBuffer.toString();
            }
            boolean b = OssCheckUtils.imageSyncCheckV2(pic);
            if (!b) {
                return this.errorJSON("上传的头像违规,请重新上传");
            }
            appUserService.uppic(user.getId(), pic);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            //腾讯三方导入
            UserShiZhi shiZhi = new UserShiZhi();
            shiZhi.setTouxiang(pic);
            shiZhi.setTengxuncode(user.getTengxuncode() + "");
            portraitTouXiangSet(shiZhi);
            return this.sucessJSON(pic, "保存成功");
        } catch (Exception e) {
            logger.error("编辑头像时异常", e);
            return this.errorJSON("系统繁忙");
        }
    }
//    public Result uppic(MultipartFile[] image) {
//        try {
//
//            //获取最新数据
//            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
//            AppUser user = appUserService.get(userId);
//
//            String pic = "";
//            //上传：循环获取file数组中得文件
//            StringBuffer stringBuffer = new StringBuffer();
//            if (image != null && image.length > 0) {
//                MultipartFile files = image[0];
//                if (!files.isEmpty()) {
//                    //判断图片大小
//                    if (files.getSize() <= 52428800) {
//                        //上传阿里云oss
//                        String ossUrl = appUserService.aliyunOssupload(files);
//                        if (isNull(ossUrl)) {
//                            return errorJSON("图片上传失败");
//                        }
//                        //拼接
//                        stringBuffer.append(ossUrl);
//                    } else {
//                        return this.errorJSON("图片大小超过限制！");
//                    }
//                }
//            } else {
//                return this.errorJSON("图片不能为空");
//            }
//            pic = stringBuffer.toString();
//            appUserService.uppic(user.getId(), pic);
//            //判断用户的体重、身高、年收入、职业是否完善
//            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
//                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
//            }
//            //腾讯三方导入
//            UserShiZhi shiZhi = new UserShiZhi();
//            shiZhi.setTouxiang(pic);
//            shiZhi.setTengxuncode(user.getTengxuncode() + "");
//            portraitTouXiangSet(shiZhi);
//            return this.sucessJSON(pic, "保存成功");
//        } catch (Exception e) {
//            logger.error("编辑头像时异常", e);
//            return this.errorJSON("系统繁忙");
//        }
//    }

    /**
     * 编辑形象照片信息
     *
     * @Param: [image 图片文件流]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/22
     * @Time: 9:41
     */
    @RequestMapping("/upxingxiang")
    @ResponseBody
    public Result upxingxiang(MultipartFile[] image, String urlImage) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            if (ObjectUtil.isNotEmpty(image)) {
                String pic = "";
                //上传：循环获取file数组中得文件
                StringBuffer stringBuffer = new StringBuffer();
                if (image != null && image.length > 0) {
                    for (int i = 0; i < image.length; i++) {
                        MultipartFile files = image[i];
                        if (!files.isEmpty()) {
                            //判断图片大小
                            if (files.getSize() <= 52428800) {
                                //上传阿里云oss
                                String ossUrl = appUserService.aliyunOssupload(files);
                                if (isNull(ossUrl)) {
                                    return errorJSON("图片上传失败");
                                }
                                boolean b = OssCheckUtils.imageSyncCheckV2(ossUrl);
                                if (!b) {
                                    return this.errorJSON("上传的图片违规");
                                }
                                //图片拼接
                                stringBuffer.append(ossUrl + ",");
                            } else {
                                return this.errorJSON("图片大小超出限制");
                            }
                        }
                    }
                    pic = stringBuffer.toString();
                }
                String img = "";
                AppUser appUser = appUserService.get(userId);
                if (StringEx.isNotNull(appUser.getXingxiang())) {
                    img = appUser.getXingxiang() + pic;
                } else {
                    img = pic;
                }
                appUserService.upxingxiang(userId, img);
                //截取掉后面的，
                pic = pic.substring(0, pic.lastIndexOf(","));
                return this.sucessJSON(pic, "成功");
            } else {
                String pic = "";
                AppUser appUser = appUserService.get(userId);

                if (StringEx.isNotNull(appUser.getXingxiang())) {
                    pic = appUser.getXingxiang() + urlImage;
                } else {
                    pic = urlImage;
                }
                appUserService.upxingxiang(userId, pic);
                return this.sucessJSON(pic, "成功");
            }


        } catch (Exception e) {
            logger.error("编辑形象照片时异常", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    /**
     * 删除形象照片
     *
     * @Param: [pic 图片信息]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/22
     * @Time: 9:58
     */
    @RequestMapping("/delxxpic")
    @ResponseBody
    public Result delxingxiangpic(String pic) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);
            if (isNull(pic)) return this.errorJSON("手机号不能为空");
            String xxpic = user.getXingxiang();
            String img = "";
            //判断图片是否是形象图片中的某一张
            if (xxpic.contains(pic)) {
                //截取掉要删除的图片路径
                String[] str = xxpic.split(",");
                for (int i = 0; i < str.length; i++) {
                    if (!pic.equals(str[i])) {
                        img += str[i].toString() + ",";
                    }
                }
                //保存图片
                appUserService.upxingxiang(user.getId(), img);
                return this.sucessJSON("成功");
            } else {
                return this.errorJSON("未获取到图片");
            }
        } catch (Exception e) {
            logger.error("删除形象照片时异常", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    /**
     * 编辑性别
     *
     * @Param: [sex 性别 1、男  2、女  3、未选择  默认3、未选择]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/22
     * @Time: 10:34
     */
    @RequestMapping("/upsex")
    @ResponseBody
    public Result upsex(Integer sex) {
        try {
            if (true) {
                return this.errorJSON("性别不能修改");
            }
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);
            if (isNull(sex)) {
                return this.errorJSON("性别不能为空");
            }
            if (sex.equals(1) || sex.equals(2)) {
                appUserService.upsex(user.getId(), sex);
            }
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("编辑性别时异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 设置支付密码
     *
     * @Param: [password 支付密码]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/28
     * @Time: 16:59
     */
    @RequestMapping("/savezhifu")
    @ResponseBody
    public Result savezhifu(String password) {
        try {
            if (StringEx.isNull(password)) {
                return this.errorJSON("支付密码不能为空");
            }
            if (password.length() != 6) {
                return this.errorJSON("支付密码只能6位");
            }
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            appUserService.upzhifumima(user.getId(), password);
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("设置支付密码异常", e);
            return this.errorJSON("系统繁忙");
        }
    }


    /**
     * 修改支付密码
     *
     * @Param: [phone, code]
     * @return: com.vf.admin.common.entity.Result
     * @Author: zhouyunyi
     * @Date: 2021/07/28
     * @Time: 17:23
     */
    @RequestMapping("/upzhifumima")
    @ResponseBody
    public Result upzhifumima(String phone, String code) {
        try {
            if (StringEx.isNull(phone)) {
                return this.errorJSON("手机号不能为空");
            }
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);
            if (!phone.equals(user.getLoginname())) {
                return this.errorJSON("手机号输入不正确");
            }
            if (StringEx.isNull(code)) {
                return this.errorJSON("验证码不能为空");
            }
            if (phone.toLowerCase().contains("script")) {
                return this.errorJSON("请不要做非法攻击！");
            }
            if (code.toLowerCase().contains("script")) {
                return this.errorJSON("请不要做非法攻击！");
            }
            boolean exits = redisUtil.hasKey(RedisKeys.zcyzm + phone);
            if (!exits) {
                return this.errorJSON("验证码不能为空！");
            }
            String values = redisUtil.get(RedisKeys.zcyzm + phone).toString();
            if (StringEx.isNull(values)) {
                return this.errorJSON("验证码已过期，请重新获取验证码！");
            }
            if (!values.trim().equals(code)) {
                //return this.errorJSON("验证码不正确，请重新输入！");
            }
            //删除验证码
            redisUtil.del(RedisKeys.zcyzm + phone);
            return this.sucessJSON("修改成功");
        } catch (Exception e) {
            logger.error("修改支付密码时异常", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }

    /**
     * 修改，保存身高
     *
     * @Param: [shengao  身高]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/upshengao")
    @ResponseBody
    public Result upshengao(Integer shengao) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(shengao)) {
                return this.errorJSON("身高不能为空");
            }
            String sg = ClientConstants.getShenGaoMap().get(shengao);

            appUserService.upshengao(user.getId(), sg, shengao);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改身高异常", e);
            return this.errorJSON("系统繁忙");
        }
    }


    /**
     * 修改，保存体重
     *
     * @Param: [tizhong  体重]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/uptizhong")
    @ResponseBody
    public Result uptizhong(Integer tizhong) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(tizhong)) {
                return this.errorJSON("体重不能为空");
            }
            String tz = ClientConstants.getTiZhongMap().get(tizhong);
            appUserService.uptizhong(user.getId(), tz, tizhong);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改体重异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 修改，保存体重
     *
     * @Param: [tizhong  体重]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/upWeChatNum")
    @ResponseBody
    public Result upweChatNum(String weChatNum) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(weChatNum)) {
                return this.errorJSON("微信名称不能为空");
            }

            appUserService.upweChatNum(user.getId(), weChatNum);

            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改体重异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 修改，保存年收入
     *
     * @Param: [tizhong  体重]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/upnianshouru")
    @ResponseBody
    public Result upnianshouru(Integer nianshouru) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(nianshouru)) {
                return this.errorJSON("年收入id不能为空");
            }
            String nian = ClientConstants.getNianShouRuMap().get(nianshouru);
            appUserService.upnianshouru(user.getId(), nian, nianshouru);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }

            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改体重异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 修改，保存年收入
     *
     * @Param: [tizhong  体重]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/upxueli")
    @ResponseBody
    public Result upxuelie(Integer xueliru) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(xueliru)) {
                return this.errorJSON("学历不能为空");
            }
            String xueli = ClientConstants.getEduRuMap().get(xueliru);
            appUserService.upxueli(user.getId(), xueli, xueliru);
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }

            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改学历异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 修改，保存职业
     *
     * @Param: [zhiyecode  职业code]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/upzhiye")
    @ResponseBody
    public Result upzhiye(Integer zhiyecode) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);

            if (isNull(zhiyecode)) {
                return this.errorJSON("职业编号不能为空");
            }
            AppZhiye zhiye = appZhiyeService.getCode(zhiyecode);
            if (org.springframework.util.StringUtils.isEmpty(zhiye)) {
                return this.errorJSON("职业不存在");
            }
            appUserService.upzhiye(user.getId(), zhiye.getCode(), zhiye.getName());
            //判断用户的体重、身高、年收入、职业是否完善
            if (!isNull(user.getNianshouru()) && !isNull(user.getShengao()) && !isNull(user.getTizhong()) && !isNull(user.getZhiyename())) {
                appDailyTasController.getAwardOnce(user.getId(), ClientConstants.TaskOnce.PERFECT_INFO);
            }
            return this.sucessJSON("保存成功");
        } catch (Exception e) {
            logger.error("修改体重异常", e);
            return this.errorJSON("系统繁忙");
        }
    }

    /**
     * 修改，保存标签
     *
     * @Param: [zhiyecode  职业code]
     * @return: com.vf.admin.common.entity.Result
     * @Author: xzx
     */
    @RequestMapping("/upBiaoqian")
    @ResponseBody
    public Result upBiaoqian(String biaoqian) {
        try {
            //获取最新数据
            Integer userId = (Integer) redisUtil.get(RedisKeys.userToken + request.getHeader(ClientConstants.client_toke));
            AppUser user = appUserService.get(userId);
            if (isNull(biaoqian)) {
                return this.errorJSON("标签不能为空");
            }
            List<AppBiaoqian> list = appBiaoqianService.alllist(biaoqian);
            StringBuffer stringBuffer = new StringBuffer();
            for (AppBiaoqian appBiaoqian : list) {
                stringBuffer.append("," + appBiaoqian.getName());
            }
            appUserService.upbiaoqian(user.getId(), biaoqian, stringBuffer.toString().substring(1));

            appDailyTasController.getAwardOnce(userId, ClientConstants.TaskOnce.PERFECT_INFO);
            return this.sucessJSON("成功");
        } catch (Exception e) {
            logger.error("Modify abnormal weight", e);
            return this.errorJSON("网络繁忙，请稍后重试");
        }
    }
}
